package com.example.simpletodolist;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class ToDoListDatabase extends SQLiteOpenHelper  {
	
	private static final String TAG = "ToDoListDatabase";
	private static final String DATABASE_NAME = "todo";
	private static final int DATABASE_VERSION = 1;
	

	public static final String COL_TITLE = "title";
	public static final String COL_BODY = "body";
	public static final String COL_DATE = "deadline";
	public static final String COL_TIME = "deadlinetime";
	public static final String KEY_ROWID = "_id";
	public static final String TABLE_TODO = "toDoList";
	

	private static final String DATABASE_CREATE = 
			"create table " + TABLE_TODO +
			" (" + KEY_ROWID + " integer primary key autoincrement, " +
			COL_TITLE + " text not null, "+
			COL_BODY  +" text not null, "+
			COL_DATE  +" text not null, " +
			COL_TIME  +" text not null)";	// I'm assuming the date should be text because there isn't a date datatype in sqlite
																					// http://www.sqlite.org/datatype3.html

	public ToDoListDatabase(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		try {
		db.execSQL(DATABASE_CREATE);
		} catch (Exception ex) {
			Log.w(TAG, ex.getMessage().toString());
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(TAG, "Upgrading database. Existing contents will be lost. ["
	            + oldVersion + "]->[" + newVersion + "]");
		db.execSQL("DROP TABLE IF EXISTS "+TABLE_TODO);
		onCreate(db);
	}
	
	public void close() {
		this.close();
	}
		
}
